home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / NLoad / NLoad.m < prev    next >
Encoding:
Text File  |  1991-04-12  |  2.8 KB  |  130 lines

  1. #import <c.h>
  2. #import <stdlib.h>
  3.  
  4. #import <nikit/NIOpenPanel.h>
  5.  
  6. #import "NLoad.h"
  7. #import "NLoadCommon.h"
  8.  
  9. #import "LoadView.h"
  10. #import "RPCLoadView.h"
  11. #import "UDPLoadView.h"
  12.  
  13. #define BORDER 3
  14.  
  15. #define PATH "/machines"
  16. #define PROMPT "Host to monitor:"
  17.  
  18. static NXDefaultsVector myDefaults = { {"Hosts", NULL},
  19.                        {"LocalUpdateSeconds", "10"},
  20.                        {"RemoteUpdateSeconds", "60"},
  21.                        {"HostsWaitSeconds", "4"},
  22.                        {"QueueLength", "-1"},
  23.                        {NULL} };
  24.  
  25. @implementation NLoad : Application
  26.  
  27. + initialize
  28. {
  29.     NXRegisterDefaults(APPLICATION, myDefaults);
  30.     return [super initialize];
  31. }
  32.  
  33. - appDidInit:sender
  34. {
  35.     NXRect cRect, fRect;
  36.     id icon = [sender appIcon], aView;
  37.      const char *string;
  38.      char *hostPtr, *nextHostPtr;
  39.     
  40.     [[panel = [NIOpenPanel new] setDirectoryPath:PATH] setListTitle:PROMPT];
  41.     
  42.     xLoc = yLoc = 0.0;
  43.  
  44.     [self getScreenSize:&size];
  45.  
  46.     [icon getFrame:&fRect];
  47.  
  48.     [Window getContentRect:&cRect forFrameRect:&fRect style:[icon style]];
  49.  
  50.     cRect.origin.x = cRect.origin.y = BORDER;
  51.     cRect.size.width -= BORDER * 2;
  52.     cRect.size.height -= BORDER * 2;
  53.  
  54.     [[icon contentView] addSubview:(aView = [[LoadView alloc] initFrame:&cRect])];
  55.  
  56.     [icon display];
  57.  
  58.     [aView startTimer];
  59.  
  60.     if ((string = getDefault("Hosts")) == NULL) return self;
  61.  
  62.     nextHostPtr = NXCopyStringBuffer(string);
  63.  
  64.     while (nextHostPtr != NULL) {
  65.         hostPtr = nextHostPtr;
  66.         if ((nextHostPtr = index(hostPtr, ';')) != NULL) *nextHostPtr++ = '\0';
  67.         [self addHost:hostPtr];
  68.         }
  69.  
  70.     return self;
  71. }
  72.  
  73. - addHost:(const char *) string
  74. {
  75.     NXRect cRect, fRect;
  76.     id aWindow, aView;
  77.      char *hostPtr, *namePtr, *sPtr, *typePtr;
  78.  
  79.     NXSetRect(&cRect, xLoc, yLoc, WIDTH, HEIGHT);
  80.     [Window getFrameRect:&fRect forContentRect:&cRect style:NX_TITLEDSTYLE];
  81.  
  82.     aWindow = [[Window alloc] initContent:&cRect style:NX_TITLEDSTYLE
  83.         backing:NX_BUFFERED buttonMask:NX_CLOSEBUTTONMASK defer:NO];
  84.  
  85.     namePtr = NXCopyStringBuffer(string);
  86.     if ((sPtr = index(namePtr, '.')) != NULL) *sPtr = '\0';
  87.     [aWindow setTitle:namePtr];
  88.     free(namePtr);
  89.  
  90.     cRect.origin.x = cRect.origin.y = BORDER;
  91.     cRect.size.width -= BORDER * 2;
  92.     cRect.size.height -= BORDER * 2;
  93.  
  94.     hostPtr = NXCopyStringBuffer(string);
  95.     if ((typePtr = rindex(hostPtr, ':')) != NULL && strcmp(typePtr, ":udp") == 0) {
  96.         *typePtr = '\0';
  97.         aView = [[UDPLoadView alloc] initFrame:&cRect];
  98.         }
  99.     else aView = [[RPCLoadView alloc] initFrame:&cRect];
  100.     [aView setHostName:hostPtr];
  101.     free(hostPtr);
  102.     
  103.     [[aWindow display] orderFront:nil];
  104.  
  105.     [[aWindow contentView] addSubview:aView];
  106.  
  107.     [[aView display] startTimer];
  108.     
  109.     xLoc += fRect.size.width;
  110.     if((xLoc + fRect.size.width) > size.width) { xLoc = 0.0; yLoc += fRect.size.height; }
  111.     
  112.     return self;
  113. }
  114.  
  115. - addNIHost:sender
  116. {
  117.     if ([panel runModal] == NX_OKTAG) [self addHost:[panel directory]];
  118.  
  119.     return self;
  120. }
  121.  
  122. - setVersion:anObject
  123. {
  124.     [(version = anObject) setStringValue:VERSION];
  125.     
  126.     return self;
  127. }
  128.  
  129. @end
  130.